//
//  ViewController.m
//  SqliteDemo
//
//  Created by hu ping kang on 2018/7/30.
//  Copyright © 2018年 hu ping kang. All rights reserved.
//
#import "SQLitePlugin.h"
#import "ViewController.h"

#define DOC (NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, NO).firstObject)
@interface ViewController ()
{
    SQLitePlugin * _sqlitePlugin;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _sqlitePlugin = [[SQLitePlugin alloc]init];
    [_sqlitePlugin pluginInitialize];
}

- (IBAction)pluginInitialize:(id)sender {
    [_sqlitePlugin pluginInitialize];
}
- (IBAction)open:(id)sender {
    NSArray * arguments = @[@{@"name":@"LocalDatabase/Westlife.db",@"dblocation":@"libs"}];
    [_sqlitePlugin open:arguments];
}
- (IBAction)close:(id)sender {
    NSArray * arguments = @[@{@"path":@"LocalDatabase/Westlife.db"}];
    [_sqlitePlugin close:arguments];
}
- (IBAction)delete:(id)sender {
    NSArray * arguments = @[@{@"path":@"LocalDatabase/Westlife.db",@"dblocation":@"libs"}];
    [_sqlitePlugin delete:arguments];
}
- (IBAction)backgroundExecuteSqlBatch:(id)sender {
    NSArray * arguments = @[
                            @{
                                @"dbargs":@{
                                        @"dbname":@"LocalDatabase/Westlife.db",
                                        },
                                @"executes":@[
                                        //建表：
                                        @{
                                            @"params":@[],
                                            @"sql":@"create table Person(name text,age integer)",
                                            },
                                        //插入数据：
                                        @{
                                            @"params":@[],
                                            @"sql":@"insert into Person(name,age) values ('小明','20')",
                                            },
                                        @{
                                            @"params":@[],
                                            @"sql":@"insert into Person(name,age) values ('小汪','20')",
                                            },
                                        @{
                                            @"params":@[],
                                            @"sql":@"insert into Person(name,age) values ('大力','20')",
                                            },
                                        //更新数据：
                                        @{
                                            @"params":@[],
                                            @"sql":@"update Person set age = '23' where name = '小汪'",
                                            },
                                        //条件查询
                                        @{
                                            @"params":@[],
                                            @"sql":@"select * from Person where age='20'",
                                            },
                                        //查询全部
                                        @{
                                            @"params":@[],
                                            @"sql":@"select * from Person",
                                            },
                                        //条件删除
                                        @{
                                            @"params":@[],
                                            @"sql":@"delete from Person where age = '20' and name = '大力'",
                                            },
                                        ],
                                }];
    [_sqlitePlugin backgroundExecuteSqlBatch:arguments successBlock:^(sqlite3 *sq) {
        
    } fail:^{
        
    }];
}
- (IBAction)executeSqlBatchNow:(id)sender {
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
